package network.udp;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;
//词典服务器
public class UdpDictServer extends UdpEchoServer{
    private HashMap<String,String> dictionary= new HashMap<>();
    public UdpDictServer(int port) throws SocketException {
        super(port);
        dictionary.put("cat","小猫");
        dictionary.put("dog","小狗");
        dictionary.put("horse","小马");
        dictionary.put("chicken","蔡徐坤");
        //此处可以添加任意个键值对
    }
    //start方法完全从父类这里继承下来
    //process方法要进行重写,加入翻译逻辑


    @Override
    public String process(String request) {
        //参数是英文
        //返回值是一个英文
        return dictionary.getOrDefault(request,"你要查找的单词不存在");
    }
    public void addNewWord(String word,String translation){
        dictionary.put(word,translation);
    }

    public static void main(String[] args) throws IOException {
        UdpDictServer server = new UdpDictServer(9090);
        server.start();

    }

}
